package edu.zut2.object_demo;

import java.util.Objects;

public class Student {

    private String num;
    private String name;
    private int age;

    public Student(String num, String name, int age) {
        this.num = num;
        this.name = name;
        this.age = age;
    }

    public Student() {
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 重写父类Object提供的toString 方法
     * @return
     */
    @Override
    public String toString() {
        return "name = " + name + ",num = " + num + ", age = " + age;
    }


    /**
     * 重写equals方法，实现根据属性进行比较
     */
    @Override
    public boolean equals(Object o) {
        if (o == null || this.getClass() != o.getClass()){
            return false;
        }else {
            Student student = (Student) o;
            return Objects.equals(name,student.name) && age == student.age && num.equals(student.num);
        }
    }

    @Override
    public int hashCode() {
        return Objects.hash(num, name, age);
    }
}
